package com.education.online.controller;


import com.education.common.pojo.OUserMaster;
import com.education.common.utils.ApiReturnObject;
import com.education.common.utils.DateUtil;
import com.education.online.service.OUserMasterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * 我的达人币
 *
 * @date 2020-06-16 09:54:55
 */
@Api(tags = {"PC--我的达人币"})
@RestController
@RequestMapping("/online/ousermaster")
public class OUserMasterController {

    @Autowired
    private OUserMasterService oUserMasterService;

    @ApiOperation(value = "我的达人币", httpMethod = "GET")
    @GetMapping("/masterCoin")
    public ApiReturnObject masterCoin(OUserMaster oUserMaster) {
        List<OUserMaster> oUserMasters = oUserMasterService.selectOUserMasterList(oUserMaster);
        for (OUserMaster userMaster : oUserMasters) {
            userMaster.setTime(DateUtil.dataTimeFormat(userMaster.getCreatetime()));
        }
        return new ApiReturnObject("200", "success", oUserMasters);
    }


    /**
     * feign : 远程调用添加信息
     */
    @PostMapping("/insert")
    public String insert(String context, Integer userID, Integer people) {
        OUserMaster oUserMaster = new OUserMaster();
        oUserMaster.setContext(context);
        oUserMaster.setUserId(userID);
        oUserMaster.setPeople(people);
        oUserMaster.setCreatetime(new Date());
        oUserMasterService.insertOUserMaster(oUserMaster);
        return "success";
    }

}
